package com.ai.controller.security;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.security.SysRequestPath;
import com.ai.entity.security.page.SysRequestPathPage;
import com.ai.model.param.SysRequestPathParam;
import com.ai.service.security.ISysRequestPathService;
import com.ai.common.vaild.AddGroup;
import com.ai.common.vaild.UpdateGroup;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 请求路径 接口
 *
 * @author chen
 * @since 2023-04-04 19:46:06
 */
@RestController
@RequestMapping("/sys-request-path")
public class SysRequestPathController {

    @Resource
    private ISysRequestPathService iSysRequestPathService;


    //

    @ApiOperation("分页查询")
    @PostMapping("list")
    @EnterPathParamLog
    public IPage<SysRequestPath> list(@RequestBody SysRequestPathPage page) {

        // 根据创建时间排序
        QueryWrapper<SysRequestPath> queryWrapper = page.getQuery(new QueryWrapper<>());
        IPage<SysRequestPath> iPage = iSysRequestPathService.page(page, queryWrapper);
        return iPage;
    }

    @ApiOperation("查询指定路径")
    @PostMapping("selectById/{id}")
    @EnterPathParamLog
    public CommonResponse<Object> selectById(@PathVariable(name = "id") Integer id) {
        SysRequestPath byId = iSysRequestPathService.getById(id);
        return CommonResponse.ok("查询成功").setData(byId);
    }

    //新增
    @ApiOperation("新增路径")
    @PostMapping("add")
    @EnterPathParamLog
    public CommonResponse<String> add(@RequestBody @Validated({AddGroup.class}) SysRequestPathParam requestPathParam) {
        return iSysRequestPathService.add(requestPathParam);
    }

    //删除
    @ApiOperation("删除路径")
    @PostMapping("delete/{id}")
    @EnterPathParamLog
    public CommonResponse<String> delete(@PathVariable(name = "id") Integer id) {
        boolean b = iSysRequestPathService.removeById(id);
        if (b){
            return CommonResponse.ok("删除成功");
        }else {
            return CommonResponse.error("删除失败");
        }
    }
    @ApiOperation("更新路径信息")
    @PostMapping("update")
    @EnterPathParamLog
    public CommonResponse<String> update(@RequestBody @Validated({UpdateGroup.class})SysRequestPathParam requestPathParam) {
        return iSysRequestPathService.updateSysRequestPath(requestPathParam);

    }
}

